<?php
/*
	商品出库
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?:'add';
if($_RQ['op']=='add'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$post['depot_id']=$depot_id;
		$data=array_fields(array('num','depot_id','remark'),$post);
		$id=intval($post['id']);
		if(!$id){
			exi('请先选择商品！','error');
		}
		if(!$data['num']){
			exi('请先设置出库数量！','error');
		}
		$depot_goods=$this->pdo_get('depot_goods',array('id'=>$id));
		if(!$depot_goods){
			exi('指定商品不存在！','error');
		}
		if($depot_goods['total']<$data['num']){
			exi('商品库存不足！','error');
		}
		$this->model('depot')->out_goods($data,$depot_goods);
		exi('出库成功~','','/depot.out_log/');
	}
	$return['item']=array();
	$return['htmls']=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'choose_up','name'=>'id','title'=>'出库商品ID','action'=>'/depot.goods/choose'),
			array('type'=>'string','name'=>'title','title'=>'出库商品名称','read'=>true),
			array('type'=>'image','name'=>'image','title'=>'出库商品图片','read'=>true),
			array('type'=>'string','name'=>'total','title'=>'商品当前库存','read'=>true),
			array('type'=>'string','name'=>'num','title'=>'出库数量'),
			array('type'=>'text','name'=>'remark','title'=>'备注'),
		),
	);
	exi($return);
}